package com.yds.xutils_facrotypattern.https;

import android.util.Log;

import com.google.gson.Gson;

/**
 * @author YDS
 * @date 2021/5/25
 * @discribe http 管理工具
 */
@SuppressWarnings("all")
public class HttpManager {

    public static final String TYPE_NORMAL = "xutils_normal";
    public static final String TYPE_RESTFUL = "xutils_restful";
    public static final String TYPE_DEFAULT = TYPE_NORMAL;

    /**
     * 默认引擎
     *
     * @return
     */
    public static IHttpsMethodListener request() {
        return request(TYPE_DEFAULT);
    }

    /**
     * 指定引擎
     *
     * @param type
     * @return
     */
    public static IHttpsMethodListener request(String type) {
        switch (type) {
            case TYPE_RESTFUL:
                return new XutilsHttpRestfulEngine();
            default:
                return new XutilsHttpNormalEngine();
        }
    }

    /**
     * @auther 于德水
     * created at 2021/5/25 15:18
     * 方法描述：转换javabean实体类
     */
    public static <T> T initJavaBean(String result, Class<T> clz) {
        try {
            T t = new Gson().fromJson(result, clz);
            return t;
        } catch (Exception e) {
            Log.i("X-utils", "转换javabean实体类 Exception = \n" + e.getMessage());
            return null;
        }
    }

}
